package com.ddone.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ddone.service.OrderService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ddone
 * @date 2024/4/6-15:35
 */
@RestController
@RequestMapping("/order")
@RefreshScope
// 配置刷新配置文件
public class OrderController {

    @Resource
    private OrderService orderService;

    @Value("${order.app.name}")
    private String appName;

    @Value("${mysql.url}")
    private String mysqlUrl;

    @Value(("${redis.host}"))
    private String redisHost;

    @GetMapping("/{userId}/{productId}/{count}")
    public Boolean save(@PathVariable("userId") String userId,
                        @PathVariable("productId") String productId,
                        @PathVariable("count") Integer count
    ) {
        return orderService.saveOrder(userId, productId, count);
    }

    @GetMapping
    @SentinelResource(value = "testResource")
    public String hello(@RequestParam(value = "pid",required = false) String productId,
                        @RequestParam(value = "count",required = false) Integer count){
        return "productId="+productId+" count="+count;
    }


}
